fix(optimizer): Quotation issue in canonicalize_internal_names#7795
Closed
fivetran-kwoodbeck wants to merge 1 commit into
Closed
fix(optimizer): Quotation issue in canonicalize_internal_names#7795fivetran-kwoodbeck wants to merge 1 commit into
fivetran-kwoodbeck wants to merge 1 commit into
Conversation
Contributor
SQLGlot Integration Test Results✅ All tests passedComparing:
Overallmain: 192428 total, 153523 passed (pass rate: 79.8%) sqlglot:optimizer/bug-canonicalize-internal-names-alias-collision: 180234 total, 142378 passed (pass rate: 79.0%) Transitions: Dialect pair changes: 0 previous results not found, 3 current results not found ✅ All tests passed |
Collaborator
|
@fivetran-kwoodbeck how did you test this? I don't see any issue: >>> from sqlglot import parse_one
>>> from sqlglot.optimizer.qualify import qualify
>>> from sqlglot.optimizer.canonicalize_internal_names import canonicalize_internal_names
>>>
>>> sql = "SELECT a AS a, b AS c, d AS renamed FROM cat.db.t WHERE a > b AND b > 0 AND d < 0"
>>> ast = parse_one(sql)
>>> qualified = qualify(ast, schema={"cat": {"db": {"t": {"a": "int", "b": "int", "d": "int"}}}})
>>> canonicalized = canonicalize_internal_names(qualified)
>>>
>>> canonicalized.sql()
'SELECT "_t0"."a" AS "a", "_t0"."b" AS "c", "_t0"."d" AS "renamed" FROM "cat"."db"."t" AS "_t0" WHERE "_t0"."a" > "_t0"."b" AND "_t0"."b" > 0 AND "_t0"."d" < 0' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
canonicalize_internal_nameswas quoting unqualified base column references when its name happened to match the top level output alias. This produced inconsistent identifier quoting in the canonical output. This violates the rule that base-table column references are part of the data contract and must be preserved verbatim.The fix narrows the rewrite so it only fires when the alias is actually being renamed.
Query: